CPP=g++
FC=gfortran
DEBUG=-g
CPPOPTS=-fPIC -fsigned-char
FCOPTS=-fPIC
LIBIFXDIR=..
LIBIFXINC=-I$(LIBIFXDIR)/include
GFORTRANLIBS=-lgfortran -lgfortranbegin

ifndef INFORMIXDIR
INFORMIXDIR=/usr/local/informix
#INFORMIXDIR=/opt/informix
endif
CFORTRANDEFS=-Df2cFortran -I/usr/include
INFORMIXDEF=-DLINUX -DIT_DO_NOT_SIMULATE_BOOL -DIT_HAS_DISTINCT_LONG_DOUBLE -DIT_COMPILER_HAS_LONG_LONG -DIT_DLLIB -DMITRACE_OFF
INFORMIXINCLUDES=-I$(INFORMIXDIR)/incl/c++ -I$(INFORMIXDIR)/incl/dmi -I$(INFORMIXDIR)/incl/esql -I$(INFORMIXDIR)/incl
INFORMIXLIBDIRS=-L$(INFORMIXDIR)/lib/c++ -L$(INFORMIXDIR)/lib/dmi -L$(INFORMIXDIR)/lib/esql -L$(INFORMIXDIR)/lib
INFORMIXLIBRARIES=-lifc++ -lifdmi -lifsql -lifasf -lifgen -lifos -lifgls -lifglx
INFORMIXSYSLIBS=-lm -ldl -lcrypt -lnsl
INFORMIXLINKEROPTS=-Wl,-rpath,$(INFORMIXDIR)/lib/c++ -Wl,-rpath,$(INFORMIXDIR)/lib/dmi -Wl,-rpath,$(INFORMIXDIR)/lib/esql -Wl,-rpath,$(INFORMIXDIR)/lib -Wl,-rpath,$(LIBIFXDIR)
INFORMIXENV=$(INFORMIXDEF) $(INFORMIXINCLUDES) $(INFORMIXLIBDIRS) $(INFORMIXLIBRARIES) $(INFORMIXSYSLIBS) $(INFORMIXLINKEROPTS)
IFX2F=ifx2f


all: Makefile $(LIBIFXDIR)/lib$(IFX2F).so example1.exe

$(LIBIFXDIR)/lib$(IFX2F).so:
	make -C $(LIBIFXDIR)

%.exe: %.o
	$(CPP) $(DEBUG) $(CPPOPTS) -o $@ $< -L$(LIBIFXDIR) -l$(IFX2F) $(GFORTRANLIBS) $(INFORMIXENV) 

%.o: %.f90
	$(FC) $(DEBUG) $(FCOPTS) $(CFORTRANDEFS) $(LIBIFXINC) -o $@ -c $<

clear: clean
clean:
	rm -f *.o *.exe

distclean:
	rm -f *.o
	rm -f *.exe

